﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using Bzure.Common.Core;
using Bzure.Apps.Security.ViewModels;
using Bzure.Apps.Security;

namespace System
{
   
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
    internal class SecurityAppFilter : FilterAttribute, IActionFilter
    {
        public SecurityAppFilter(PageControllerItems PageViewItem)
        {
            this.PageViewItem = PageViewItem;
        }
        public PageControllerItems PageViewItem { get; private set; }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (ApplicationStartContextSecurityMVCExtensions.ActionFilterBuilder.IsNotNull())
            {
                ApplicationStartContextSecurityMVCExtensions.ActionFilterBuilder(this.PageViewItem).OnActionExecuted(filterContext);
            }
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (ApplicationStartContextSecurityMVCExtensions.ActionFilterBuilder.IsNotNull())
            {
                ApplicationStartContextSecurityMVCExtensions.ActionFilterBuilder(this.PageViewItem).OnActionExecuting(filterContext);
            }
        }
    }
    [Serializable]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
    internal class AccountRegisterAuthorizeFilter : AuthorizeAttribute
    {
        [Obsolete("属性被禁用，请使用CustomerRoles属性", true)]
        public new string Roles
        {
            get;

            set;
        }
        [Obsolete("属性被禁用，请使用CustomerRoles属性", true)]
        public new string Users
        {
            get;

            set;
        }
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (ApplicationStartContextSecurityMVCExtensions.allowAnonymousRegister)
                return true;
            if (httpContext.User.Identity.IsAuthenticated && Actor.Me.ContainDroit<AdministrationRights>(ApplicationStartContextSecurityMVCExtensions.administrationRight))
                return true;
            return false;
        }
    }
}
